/**
* @Description: WoShop商城
* @Author: 梧桐
* @Copyright: 武汉一一零七科技有限公司©版权所有
* @Link: www.wo-shop.net
* @Contact: QQ:2487937004
*/
<template>
  <view class="index_class" >
    
    <view class="cont-adddres">
      <view class="phone" v-for="(time,index) in addresList" :key="index" >
        <i class="iconfont icon_e712" style="width:20%"></i>
        <view class="tap_address" @click="isconfirmClick(time)">
          <view>{{time.contacts}}  <text>  {{time.phone}}</text></view>
          <text>{{time.pro_name}}{{time.city_name}}{{time.area_name}}  {{time.address}}</text>
        </view>
        <div class="setting">
          <div v-if="time.moren" >
            <i class="iconfont icon_e632" ></i>&nbsp;&nbsp;{{$t('默认')}}
          </div>
          <div v-else></div>
          <div class="setting_btn">
            <div @click="getnav('/pagesB/my/editAddress?addrId=' + time.id)"><i class="iconfont icon_e671"></i> {{$t('编辑')}}</div>
            <div @click="handleAlert(time.id)"><i class="iconfont icon_e63a"></i> {{$t('删除')}}</div>
          
          </div>
        </div>
        <image class="p_bottom" src="/static/images/img/address_img.png" />
      </view>
      <u-empty v-if="addresList.length===0"  :src="STATICURL+'images/nullStatus/noList.png'" margin-top="200" icon-size="300"  :text="$t('暂无数据')"></u-empty>
    </view>
    <view class="add_shou" @click="getnav('/pagesB/my/newAddress')">
      {{$t('添加收货地址')}}
    </view>
  </view>
</template>

<script>
let page = 1
export default {
  onLoad(option){
    if(option.isconfirm) {
      this.isconfirm = option.isconfirm
    }
  },
  data(){
    return {
      addresList:[],
      isconfirm:false, // 是否确认订单选择地址
    }
  },
  onShow(){
    this.getAddressList()
    
  },
  methods: {
    isconfirmClick(data){
      if(this.isconfirm) {
        this.$store.commit('editAddress',data)
        this.getback()
      }
    },
    getAddressList(){
      this.$http.getAddressList({
        page:page
      }).then(res=>{
        if(res.status == 200) {
          this.addresList = res.data
        }
      })
    },
    handleAlert(id){
      this.$showModal({content:this.$t('确认删除吗')+'？'}).then(resModal=>{
        if(resModal.confirm) {
          this.$http.getAddressdel({dz_id:id}).then(res=>{
            if(res.status == 200) {
              this.$toast(res.mess)
              this.addresList.forEach( (element,index) => {
                if(element.id == id) {
                  this.addresList.splice(index,1)
                }
              });
            }
          })
        }
        
      })
    },
    
    
  },
}
</script>

<style>
page {
  height: 100%;
  background-color: #f4f4f4;
}
</style>
